package concurrence.basic;

import org.apache.commons.lang3.RandomStringUtils;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class IntDemo {
    public static void main(String[] args) throws InterruptedException {
        List<String> list = new ArrayList<>();
        for(int i=0;i<100000;i++) {
            list.add(RandomStringUtils.random(300));
        }
        ConcurrentHashMap<String,String> map = new ConcurrentHashMap<>(30000);
        long start = System.currentTimeMillis();
        Thread thread = new Thread(() -> {
            Enumeration<String> keys = map.keys();
            if(keys.hasMoreElements()) {
                map.remove(keys.nextElement());
            }
        });
        thread.setDaemon(true);
        thread.start();
        list.forEach(e->map.put(e,String.valueOf(System.currentTimeMillis())));
        System.out.println("run over"+map.size() + "|cost:" + (System.currentTimeMillis()-start));
    }
}
